package com.ruoyi.system.WebController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ByIcs;
import com.ruoyi.system.service.IByIcsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: Zhangyuting
 * @Desctription: TODO
 * @Date: Created in 2025/8/20 11:34
 * @Version: 1.0
 */
@RestController
@RequestMapping("/byWeb/ics")
public class WebByIcsController  extends BaseController {
    @Autowired
    private IByIcsService byIcsService;

    /**
     * 查询ICS列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ByIcs byIcs)
    {
        startPage();
        List<ByIcs> list = byIcsService.selectByIcsList(byIcs);
        return getDataTable(list);
    }

    /**
     * 查询ICS列表
     */
    @GetMapping("/listFirst")
    public TableDataInfo listFirst(ByIcs byIcs)
    {
//        startPage();
        List<ByIcs> list = byIcsService.selectByIcsFirstList(byIcs);
// 按 code 升序排序（默认自然顺序，字符串按字典序）
        list = list.stream()
                .sorted(Comparator.comparing(ByIcs::getCode)) // 提取 code 字段排序
                .collect(Collectors.toList());
        return getDataTable(list);
    }
}
